
Page({
  data: {
    pluginOptionsLike: {
      // 注意：每日爆款、今日福利 pid 参数为 refpid，没有 pageSize，maxPageNum 参数
      pid: 'mm_1210180140_1779150397_110912400421', // 当前插件的淘客 pid  注意pid前后一定不能随意加空格！！！
      pageSize: 6, // 每页个数，默认 10
      maxPageNum: 100
    },
    pluginOptionsFuli: {
      // 注意：每日爆款、今日福利 pid 参数为 refpid，没有 pageSize，maxPageNum 参数
      refpid: 'mm_1210180140_1779150397_110914150386', // 当前插件的淘客 pid  注意pid前后一定不能随意加空格！！！
    },
    pluginOptionsBao: {
      // 注意：每日爆款、今日福利 pid 参数为 refpid，没有 pageSize，maxPageNum 参数
      refpid: 'mm_1210180140_1779150397_110908050415', // 当前插件的淘客 pid  注意pid前后一定不能随意加空格！！！
    },
    showComponent:false,
    slider: [],
    placeholder: '购物100%有返利',
  },
  onLoad() {
    var that = this;
    that.getIndexData()
  },
  getIndexData(){
    var that = this;
    my.request({
      url: 'https://tyg.zwbysgs.cn/api/' + 'taobao/indexData', // 该url是您自己的服务地址，实现的功能是服务端拿到authcode去开放平台进行token验证
      success: (res) => {
        console.log(res);
        that.setData({
          'slider': res.data.data.slider,
          'placeholder': res.data.data.placeholder
        })
      }
    });
  },
  onReachBottom() {
    this.setData({
      loadMoreTime: (this.data.loadMoreTime || 0) + 1
    });
  },
  onYitao(e){
    my.navigateToMiniProgram({
     appId: '2018091261350219',//收藏有礼小程序的appid，固定值请勿修改
     path: '/pages/h5pages/h5pages?targetURI=https://mo.m.taobao.com/etao/tmpl_mini_butie_b?pid=mm_1210180140_1782900400_110684150201&union_lens=lensId%3APUB%401595311117%400baf7c5e_0fc4_1736ff3d6ab_05c0%4001'
    });
  },
  onWithdraw(){
    my.navigateToMiniProgram({
      appId: '2021001157608051',
      path: 'packageA/pages/withdraw/withdraw'
    });
  },
  onSearch(){
    var that = this;
    my.navigateToMiniProgram({
      appId: '2021001157608051',
      path: 'pages/list/list?word=' + that.data.placeholder
    });
  },
  onTypePage(e){
    var that = this;
    let index = e.currentTarget.dataset.index;
    let type = that.data.slider[index]['type'];
    let link = that.data.slider[index]['link'];
    if(type == 'yitao'){
      my.navigateToMiniProgram({
        appId: '2018090761255717',//收藏有礼小程序的appid，固定值请勿修改
        path: 'pages/webview-redirect/webview-redirect?url=https://mo.m.taobao.com/etao/tmpl_mini_butie_b?pid=mm_1210180140_1782900400_110684150201&union_lens=lensId%3APUB%401595311117%400baf7c5e_0fc4_1736ff3d6ab_05c0%4001'
      });
    }
    if(type == 'taobao'){
      my.loadPlugin({
        plugin: '3000000027034925@*', 
        success() {
          my.navigateTo({
            url: `dynamic-plugin://3000000027034925/index?page_url=${link}`, // 商业授权插件
          });
        }
      })
    }
    if(type == 'ele'){
      my.navigateToMiniProgram({
        appId: '2018090761255717',
        path:'pages/webview-redirect/webview-redirect?url=' + link
      });
    }
    if(type == 'page'){
      my.navigateToMiniProgram({
        appId: '2021001157608051',
        path: link
      });
    }
    if(type == 'miniProgram'){
      my.navigateToMiniProgram({
        appId: link,
      });
    }
  },
});
